<?php

/**
 * Description of addAwards
 * 添加奖励信息
 * 
 * @author ddj
 */

class AddAwardsInfo extends AddInformation{
    private $awards;
    private $queryStr;
    
    function __construct($awards=null) {
        $this->awards = $awards;
        $this->queryStr = sprintf('insert into Awards(name, awardPerson, source, time)'.
                                        'values("%s", "%s", "%s", "%s")', 
                                        $this->awards->name, $this->awards->awardPerson,
                                        $this->awards->source, $this->awards->time
                                    );
        
    }
    
    public function add($linkIdentify) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->awards==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$awards as $value) {
            if( $this->awards->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        /* 匹配日期 */
        $timePattern = '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/';       // 日期的正则表达式模式
        if( preg_match($timePattern, $this->awards->time)==0 ){
            return false;
        }
        return true;
    }

}
